package com.liuyjy.base.mybatisplus.handler;

import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
import com.liuyjy.base.mybatisplus.cache.TableSuffixCache;
import com.liuyjy.base.mybatisplus.util.TableNameUtil;

/**
 * 按id取模分表处理器
 */
public class ModTableNameParser implements TableNameHandler {


    @Override
    public String dynamicTableName(String sql, String tableName) {
        Object suffix = TableSuffixCache.getSuffix();
        if (suffix == null || "".equals(suffix)) {
            throw new RuntimeException("请设置下标值");
        }
        return TableNameUtil.getModTableName(Long.parseLong(suffix.toString()), tableName);
    }
}
